//
//  ChangeMessageViewController.m
//  QuanZiChat
//
//  Created by lanou3g on 15/11/28.
//  Copyright © 2015年 ZhongHongLin. All rights reserved.
//

#import "ChangeMessageViewController.h"

@interface ChangeMessageViewController ()
@property (weak, nonatomic) IBOutlet UITextField *textFiled;

@end

@implementation ChangeMessageViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    
    // Do any additional setup after loading the view.
}

-(void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{
    [self.textFiled resignFirstResponder];
}

//返回上一界面
- (IBAction)getBackLastVC:(id)sender {
    
    [self dismissViewControllerAnimated:YES completion:nil];
}
//保存数据
- (IBAction)saveTheData:(id)sender {
    
    AVUser *user = [AVUser currentUser];
    if (![self.textFiled.text isEqualToString:@""]) {
        //上传昵称
        if (self.number == 0) {
            
            
            [user setObject:self.textFiled.text forKey:@"nickName"];
            [user saveInBackgroundWithBlock:^(BOOL succeeded, NSError *error) {
                
                if (succeeded) {
                    NSLog(@"上传昵称成功");
                    
                    [self dismissViewControllerAnimated:YES completion:nil];
                }else{
                    NSLog(@"%@",error);
                }
            }];
        }
        //上传个性签名
        if (self.number == 6) {
            
            [user setObject:self.textFiled.text forKey:@"IndividualitySignature"];
            [user saveInBackgroundWithBlock:^(BOOL succeeded, NSError *error) {
                
                if (succeeded) {
                    NSLog(@"上传个性签名成功");
                    
                    [self dismissViewControllerAnimated:YES completion:nil];
                }else{
                    NSLog(@"%@",error);
                }
            }];
        }

    }else{
        UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"错误" message:@"不能保存空的数据" preferredStyle:(UIAlertControllerStyleAlert)];
        
        UIAlertAction *alertAction = [UIAlertAction actionWithTitle:@"确定" style:(UIAlertActionStyleDefault) handler:^(UIAlertAction * _Nonnull action) {
            
        }];
        
        [alertController addAction:alertAction];
        [self showViewController:alertController sender:nil];
    }
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
